package Chapter05.cak.game;

import java.util.ArrayList;
import java.util.List;

public class GameManager {
    private List<Game> games;

    public GameManager() {
        games = new ArrayList<>();
    }

    public void addGame(Game game) {
        games.add(game);
    }

    public void removeGame(Game game) {
        games.remove(game);
    }

    public Game findGameByName(String name) {
        for (Game game : games) {
            if (game.getName().equals(name)) {
                return game;
            }
        }
        return null;
    }

    public int getTotalNumOfPlayers() {
        int total = 0;
        for (Game game : games) {
            total += game.getNumOfPlayers();
        }
        return total;
    }

    public int getNumOfPlayersByGame(String name) {
        Game game = findGameByName(name);
        if (game != null) {
            return game.getNumOfPlayers();
        }
        return 0;
    }
}

